package opera;

import book.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2022-12-20
 * Time: 10:17
 */
public class ReturnOperation implements IOperation {
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("输入你要归还的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name) &&
                    book.getBorrowed()) {
                book.setBorrowed(false);
                System.out.println("归还成功");
                return;
            }
        }
    }
}
